package com.yicheng.controller;

import com.yicheng.entity.User;
import com.yicheng.util.JwtUtil;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/user")
@CrossOrigin
public class TokenController {

    @PostMapping("/login")
    public R getToke(@RequestBody User user){
        String userId = "20221029";
        Map<String, Object> info = new HashMap<>();
        info.put("username", user.getUser());
        info.put("pass", user.getPassword());
        String token = JwtUtil.sign(userId, info);
        String id = JwtUtil.getUserId(token);
        System.out.println(token);
        System.out.println(id);
        return new R(token, "获取成功");
    }
}
